/*
 * File: DataConnection.java Author: Robert Bittle <guywithnose@gmail.com>
 */
package triperest;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.google.appengine.api.rdbms.AppEngineDriver;

/**
 * The Class DataConnection.
 */
public class DataConnection
{

    /** The connection. */
    private static Connection connection = null;

    /**
     * Connect.
     * 
     * @return true, if successful
     */
    public static boolean connect()
    {
        if (connection == null)
        {
            try
            {
                DriverManager.registerDriver(new AppEngineDriver());
                connection = DriverManager
                        .getConnection("jdbc:google:rdbms://dominionenterprises.com:triperest:triperest/triperest");
                return connection.isValid(10);
            } catch (SQLException e)
            {
                try
                {
                    DriverManager.registerDriver(new com.mysql.jdbc.Driver());
                    connection = DriverManager
                            .getConnection("jdbc:mysql://localhost:3306/triperest?user=root&password=");
                    return connection.isValid(10);
                } catch (SQLException e2)
                {
                    e.printStackTrace();
                    return false;
                }
            }
        }
        try
        {
            return connection.isValid(10);
        } catch (SQLException e)
        {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * Get Connection.
     * 
     * @return the connection
     */
    public static Connection getConnection()
    {
        return connection;
    }

}
